<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
out.clear();
String clientCookie = request.getHeader("Cookie");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>donw2-多文件演示页面</title>
    <link type="text/css" href="js/down.css" rel="Stylesheet" />
    <script type="text/javascript" src="js/jquery-1.4.min.js"></script>
    <script type="text/javascript" src="js/down.app.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/down.edge.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/down.file.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/down.folder.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/down.js" charset="utf-8"></script>
</head>
<body>
    <p>此页面演示down2功能。</p>
    <p>down2提供文件下载，文件夹下载，文件批量下载，文件自定义下载功能。</p>
    <input type="button" value="url文件下载测试" id="btn-down" />
    <input type="button" value="自定义下载名称" id="btn-down-diyname" />
    <input type="button" value="批量下载文件" id="btn-down-files" />
    <input type="button" value="下载文件夹" id="btn-down-json" />
    <input type="button" value="下载多级文件夹" id="btn-down-fd" />
    <input type="button" value="自定义下载数据" id="btn-down-svr" />
    <input type="button" value="自定义下载数据+目录" id="btn-down-svr-fd" />
    <input type="button" value="下载文件并安装" id="btn-down-run" />
    <input type="button" value="大文件下载测试" id="btn-down-big" />
    <p><a href="db/clear.jsp" target="_blank">清空数据库</a></p>
    <p><a href="vue.htm" target="_blank">vue示例</a></p>
    <p><a href="debug/file.htm" target="_blank">单文件下载</a></p>
    <p><a href="debug/empty.htm" target="_blank">空文件下载测试</a></p>
    <p><a href="debug/err-fd-1.htm" target="_blank">1个空文件测试</a></p>
    <p><a href="debug/error.htm" target="_blank">错误文件下载测试</a></p>
    <p><a href="debug/limit.htm" target="_blank">名称长度限制测试</a></p>
    <p><a href="debug/nor-repeat.htm" target="_blank">正常重复数据下载测试</a></p>
    <p><a href="debug/err-repeat.htm" target="_blank">错误+重复数据下载测试</a></p>
    <p><a href="debug/normal.htm" target="_blank">正常数据下载测试</a></p>
    <p><a href="debug/normals.htm" target="_blank">正常多条数据下载测试</a></p>
    <p><a href="debug/repeat.htm" target="_blank">重复数据下载测试</a></p>
    <div id="downDiv"></div>
    <script type="text/javascript" language="javascript">
        var downer = new DownloaderMgr();
        downer.Config["Folder"] = "";//设置默认下载路径。
        downer.Config["Cookie"] = 'JSESSIONID=<%=request.getSession().getId()%>';
        //挂载事件
        downer.event.taskCreate = function (obj) { $(document.body).append("文件ID：" + obj.fileSvr.id) + "<br/>"; };
        downer.event.downProcess = function (obj) { };
        downer.event.downStoped = function (obj) { };
        downer.event.downComplete = function (obj) { $(document.body).append('<div>本地路径：' + obj.fileSvr.pathLoc + '</div>'); };
        downer.event.downError = function (obj, err) { };
        downer.event.queueComplete = function () { $(document.body).append("<div>队列完成</div>"); };

        $(function () {
            downer.loadTo("downDiv");

            $("#btn-down").click(function () {
                var f = { fileUrl: "http://www.ncmem.com/images/ico-ftp.jpg" };
                downer.data.cur = f;
                downer.event.selFolder = function(dir){
                    if(downer.data.cur==null) return;
                    
                    setTimeout(function(){
                        downer.addUrl(downer.data.cur);
                        downer.data.cur = null;
                    },100);
                };
                if (downer.Config["Folder"] == "") { downer.openFolder(); return; }
                downer.addUrl(f);
            });

            $("#btn-down-run").click(function () {
                //if (downer.Config["Folder"] == "") { downer.openFolder(); return; }
                var f = { fileUrl: "http://localhost:8080/down2/test.exe" };
                downer.addUrl(f);
            });

            $("#btn-down-diyname").click(function () {
                if (downer.Config["Folder"] == "") { downer.openFolder(); return; }
                var f = { fileUrl: "http://res2.ncmem.com/res/images/up6.1/up.png", nameLoc: "test.png" };
                downer.addUrl(f);
            });

            $("#btn-down-files").click(function () {
                if (downer.Config["Folder"] == "") { downer.openFolder(); return; }
                var urls = [
                    { fileUrl: "http://res2.ncmem.com/res/images/ie11.png" }
                    , { fileUrl: "http://res2.ncmem.com/res/images/up6.1/down.png" }
                    , { fileUrl: "http://res2.ncmem.com/res/images/firefox.png" }
                    , { fileUrl: "http://res2.ncmem.com/res/images/edge.png" }
                    , { fileUrl: "http://res2.ncmem.com/res/images/up6.1/cloud.png" }
                    , { fileUrl: "http://res2.ncmem.com/res/images/home/w.png" }
                    , { fileUrl: "http://res2.ncmem.com/res/images/img.png" }
                ];
                downer.addUrls(urls);
            });

            $("#btn-down-json").click(function () {
                if (downer.Config["Folder"] == "") { downer.openFolder(); return; }
                var fd = {
                    nameLoc: "图片列表"
                    , files: [
                        { fileUrl: "http://res2.ncmem.com/res/images/ie11.png" }
                        , { fileUrl: "http://res2.ncmem.com/res/images/up6.1/down.png" }
                        , { fileUrl: "http://res2.ncmem.com/res/images/firefox.png" }
                        , { fileUrl: "http://res2.ncmem.com/res/images/edge.png" }
                        , { fileUrl: "http://res2.ncmem.com/res/images/up6.1/cloud.png" }
                        , { fileUrl: "http://res2.ncmem.com/res/images/home/w.png" }
                        , { fileUrl: "http://res2.ncmem.com/res/images/img.png" }
                    ]
                };
                downer.addJson(fd);
            });

            //下载多级目录
            $("#btn-down-fd").click(function () {
                if (downer.Config["Folder"] == "") { downer.openFolder(); return; }
                var fd = {
                    nameLoc: "测试文件夹"
                    , files: [
                        { fileUrl: "http://www.ncmem.com/images/ico-ftp.jpg" }
                        , { fileUrl: "http://www.ncmem.com/images/ico-up.jpg" }
                    ]
                    , folders: [
                        {
                            nameLoc: "图片1"
                            , files: [
                                { fileUrl: "http://www.ncmem.com/images/ico-ftp.jpg" }
                                , { fileUrl: "http://www.ncmem.com/images/ico-up.jpg" }
                                , { fileUrl: "http://www.ncmem.com/images/ico-capture.jpg" }
                                , { fileUrl: "http://www.ncmem.com/images/ico-imageuploader.gif" }
                                , { fileUrl: "http://www.ncmem.com/images/ico-wordpaster.gif" }
                            ]
                            , folders: [
                                {
                                    nameLoc: "软件"
                                    , files: [
                                        { fileUrl: "http://res2.ncmem.com/res/images/edit-file.png" }
                                    ]
                                }
                            ]
                        }
                    ]
                };
                downer.addJson(fd);
            });

            //自定义下载数据，db/down.jsp负责提供数据
            $("#btn-down-svr").click(function () {
                if (downer.Config["Folder"] == "") { downer.openFolder(); return; }
                var urls = [
                    { fileUrl: "http://localhost:8080/down2/db/down.jsp", nameLoc: "test.exe" }
                    , { fileUrl: "http://localhost:8080/down2/db/down.jsp", nameLoc: "test-1.exe" }
                ];
                downer.addUrls(urls);
            });

            //自定义下载数据，db/down.jsp负责提供数据
            $("#btn-down-svr-fd").click(function () {
                if (downer.Config["Folder"] == "") { downer.openFolder(); return; }
                var fd = {
                    nameLoc: "测试文件夹"
                    , files: [
                        { fileUrl: "http://localhost:8080/down2/db/down.jsp", nameLoc: "360.exe" }
                        , { fileUrl: "http://localhost:8080/down2/db/down.jsp", nameLoc: "360-1.exe" }
                        , { fileUrl: "http://localhost:8080/down2/db/down.jsp", nameLoc: "360-2.exe" }
                        , { fileUrl: "http://localhost:8080/down2/db/down.jsp", nameLoc: "360-3.exe" }
                        , { fileUrl: "http://localhost:8080/down2/db/down.jsp", nameLoc: "360-4.exe" }
                        , { fileUrl: "http://localhost:8080/down2/db/down.jsp", nameLoc: "360-5.exe" }
                        , { fileUrl: "http://localhost:8080/down2/db/down.jsp", nameLoc: "360-6.exe" }
                        , { fileUrl: "http://localhost:8080/down2/db/down.jsp", nameLoc: "360-7.exe" }
                        , { fileUrl: "http://localhost:8080/down2/db/down.jsp", nameLoc: "360-8.exe" }
                        , { fileUrl: "http://localhost:8080/down2/db/down.jsp", nameLoc: "360-9.exe" }
                        , { fileUrl: "http://localhost:8080/down2/db/down.jsp", nameLoc: "360-10.exe" }
                    ]
                };
                downer.addJson(fd);
            });

            //大文件下载测试
            $("#btn-down-big").click(function () {
                var f = { fileUrl: "http://www.ncmem.com/download/Office2016.x86.iso" };
                downer.data.cur = f;
                downer.event.selFolder = function (dir) {
                    if (downer.data.cur == null) return;

                    setTimeout(function () {
                        downer.addUrl(downer.data.cur);
                        downer.data.cur = null;
                    }, 100);
                };
                if (downer.Config["Folder"] == "") { downer.openFolder(); return; }
                downer.addUrl(f);
            });
        });
    </script>
</body>
</html>